<template>
	<view v-show="i === index">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" top="90" :down="downOption" @down="downCallback" :up="upOption"
		 @up="upCallback" @emptyclick="downCallback">
			<view v-for="(item,index) in order" :key="index" class="order-item">
				<view class="np-row" @click="navTo(item)">
					<view class="np-box-team">
						<view class="np-team">
							<image class="np-team-avatar" :src="item.avatar || '/static/images/missing-face.png'"></image>
							<text class="np-team-name">{{item.nickname}}</text>
						</view>
						<text class="np-team-type">{{item.share_text}}</text>
					</view>
					<view class="np-box-order">
						<view class="np-box-l">
							<image class="np-goods-image" :src="item.image"></image>
						</view>
						<view class="np-box-r">
							<view class="np-goods-title more-line">
								<text v-for="(item,index) in item.tags" :key="index" class="np-goods-tag" :class="item.color ? 'bg-' + item.color : 'bg-red'">{{item.name}}</text>
								<text class="pd-left">{{item.title}}</text>
							</view>
							<text class="np-order-tip">订单编号：{{item.order_id}}</text>
							<text class="np-order-tip">下单时间：{{item.time}}</text>
							<view class="np-price-box">
								<text class="np-unit">￥</text>
								<text class="np-price">{{ item.price }}</text>
							</view>
						</view>
					</view>
					<view class="np-money">
						<text class="np-money-day margin-right" v-if="item.status_text === '待结算'">{{'结算时间:' + item.rebate_time}}</text>
						<view class="np-money-sum">
							<text class="np-sum-text">{{item.status_text === '已结算' ? '已得' : '预计'}}佣金￥</text>
							<text class="np-sum-num">{{ item.money }}</text>
						</view>
					</view>
					<view class="np-btn">
						<text class="btns-btn" :class="[item.status_text === '订单失效' ? 'default' : 'pay']">{{item.status_text}}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin],
		props: {
			i: Number,
			index: {
				type: Number,
				default () {
					return 0
				}
			},
			tabs: {
				type: Array,
				default () {
					return []
				}
			},
		},
		data() {
			return {
				order: [],
				downOption: {
					auto: false,
					textColor: '#777777',
				},
				upOption: {
					auto: false,
					textColor: '#777777',
					page: {
						num: 0,
						size: 20
					},
					noMoreSize: 4,
					empty: {
						tip: '~ 没有订单 快去下单吧 ~', // 提示
					}
				},
			}
		},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let tabItem = this.tabs[this.index];
				let sentData = {};
				sentData.status = tabItem.status;
				sentData.page = page.num;
				this.$http.get('api/user/order', {params: sentData}).then(res => {
					if (page.num == 1) {
						this.order = [];
					}
					res.forEach(item => {
						this.order.push(item);
					});
					let hasNext = true;
					let curPageLen = res.length;
					if (curPageLen < 20) {
						hasNext = false;
					}
					setTimeout(() => {
						this.mescroll.endSuccess(curPageLen, hasNext);
					}, 1000);
				}).catch((error) => {
					this.mescroll.endErr();
				});
			},
			navTo(item) {
				let url = "/pages/item/tb?id=" + item.itemid;
				if (item.cate_id == 1) {
					url = "/pages/item/jd?id=" + item.itemid;
				} else if (item.cate_id == 2) {
					url = "/pages/item/pdd?id=" + item.itemid;
				}
				uni.navigateTo({
					url: url
				});
			}
		}
	}
</script>
<style>
	.order-item {
		display: flex;
		flex-direction: column;
		background: #fff;
		margin: 16rpx;
		border-radius: 20rpx;
	}

	.np-row {
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		background-color: #fff;
		margin-top: 20rpx;
		display: flex;
		flex-direction: column;
	}

	.np-box-team {
		height: 100rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		flex: 1;
	}

	.np-team {
		display: flex;
		flex-direction: row;
		align-items: center;
		flex: 1;
	}

	.np-team-avatar {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		margin-right: 10rpx;
	}

	.np-team-name {
		font-size: 28rpx;
	}

	.np-team-type {
		font-size: 28rpx;
		color: #666;
	}

	.np-box-order {
		display: flex;
		flex-direction: row;
	}

	.np-box-l {
		width: 188rpx;
		height: 188rpx;
		margin-right: 20rpx;
	}

	.np-goods-image {
		width: 188rpx;
		height: 188rpx;
		border-radius: 10rpx;
	}

	.np-box-r {
		position: relative;
		display: flex;
		flex-direction: column;
	}

	.np-order-tip {
		color: #a7a7a7;
		font-size: 22rpx;
	}

	.np-price-box {
		color: #333;
		display: flex;
		justify-content: flex-end;
		flex-direction: row;
		align-items: center;
	}

	.np-unit,
	.np-multiplier {
		font-size: 20rpx;
	}

	.np-price,
	.np-number {
		font-size: 24rpx;
	}

	.np-money {
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}

	.np-money-day {
		font-size: 22rpx;
		color: #aaaaaa;
	}

	.np-money-sum {
		padding: 0 8rpx;
		flex-direction: row;
		align-items: flex-end;
	}

	.np-sum-text {
		font-size: 22rpx;
		color: #667eea;
	}

	.np-sum-num {
		font-size: 32rpx;
		color: #667eea;
	}

	.np-btn {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		height: 80rpx;
	}

	.btns-btn {
		width: 180rpx;
		height: 50rpx;
		padding: 0 20rpx;
		border-radius: 50rpx;
		line-height: 50rpx;
		text-align: center;
		font-size: 28rpx;
		margin-left: 20rpx;
		border-style: solid;
		border-width: 1rpx;
		border-color: #ccc;
	}

	.default {
		border-color: #ccc;
		color: #666;
	}

	.pay {
		border-color: #ec652f;
		color: #ec652f;
	}

	.np-goods-title {
		font-size: 30rpx;
		line-height: 40rpx;
		margin-bottom: 15rpx;
		position: relative;
	}

	.np-goods-tag {
		font-size: 22rpx;
		font-weight: 600;
		padding: 0 8rpx;
		height: 30rpx;
		line-height: 30rpx;
		border-radius: 6rpx;
		margin-right: 5rpx;
		vertical-align: middle;
		position: relative;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		margin-top: -6.09rpx;
	}

	.pd-left {
		padding-left: 5rpx;
	}

	/*多行文本溢出省略号*/
	.more-line {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		transition: all linear 0.2s;
	}
</style>
